<template>
    <div style="padding:20px 20px 20px 20px;background:#fff;">
      <el-table :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%"
        row-key="id" border lazy :load="load">
        <el-table-column prop="username" label="会员姓名" align="center"></el-table-column>
        <el-table-column prop="name" label="消费项目" align="center"></el-table-column>
        <el-table-column prop="lable" label="消费类型" align="center"></el-table-column>
        <el-table-column prop="pay_money" label="消费金额" align="center"></el-table-column>
        <el-table-column prop="offset_money" label="账户抵扣" align="center"></el-table-column>
        <el-table-column prop="give_money" label="代金券" align="center"></el-table-column>
        <el-table-column prop="addtime" label="消费时间" align="center"></el-table-column>
        <el-table-column
          fixed="right"
          label="业绩分配"
          width="100" align="center">
          <template slot-scope="scope">
            <el-button @click="dialog(scope.row)" type="primary" icon="el-icon-edit" size="small"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="fen"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pagesize"
        :page-sizes="[5, 10, 20, 50]"      
        layout="total, sizes, prev, pager, next, jumper"
        :total="list.length">
      </el-pagination>
      <share :show="shareShow" :userArr="userArr" :id="share_id" 
      :pay="share_pay" @func="dialog" :type="share_type" 
      :shareArr="shareList"></share>
    </div>
</template>
<script>
import share from "./share"
export default {
  name: 'moneyTable',
  props:['list'],
  data(){
      return {
        currentPage:1, //初始页
        pagesize:10, //每页的数据
        show_page:true,
        nowpage:1,
        maxpage:10,
        shareShow:false,
        userArr:[],
        share_id:0,
        share_pay:0,
        share_type:0,
        shareList:[]
      }
  },
  components: {
    "share":share
  },
  created: function() {
    
  },
  methods: {
    handleSizeChange: function (size) {
        this.pagesize = size;
    },
    handleCurrentChange: function(currentPage){
      this.currentPage = currentPage;
    },
    changeLeft($event){
        $event.currentTarget.className="active";
    },
    removeLeft($event){
        $event.currentTarget.className ="tdclass";
    },
    load(tree, treeNode, resolve) {
      setTimeout(() => {
        resolve()
      }, 1000)
    },
    dialog:function(item){
      this.shareShow = !this.shareShow
      if(!item.close){
        if(item.lable == '充值消费'){
          var type = 1;
        }
        if(item.lable == '购卡消费'){
          var type = 2;
        }
        if(item.lable == '购买家居'){
          var type = 3;
        }
        this.share_id = item.id
        this.share_pay = item.pay_money
        this.share_type = type
        this.getShareInfo(item.id,type)
      }
    },
    getShareInfo:function(id,type){
      var that = this
      this.shareList = []
      var data = {
				order_id:id,
				type:type
			}
      this.$get('manage/share/info',data).then((res) => {
        if(res.data.length > 0){
          that.shareList = res.data
        }else{
          if(that.userArr.length == 0){
            that.getUser()
          }
        }
      })
    },
    getUser:function(){
      var data = {oa_id:localStorage.getItem('oa_id')}
      var that = this
      this.$get('pc/staff/all',data).then((res) => {
          that.userArr = res.data
      })
    }
  }
};
</script>
<style>
.fen{text-align:center;}
</style>